package com.lib.online.controller.rest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lib.online.model.Reading;
import com.lib.online.model.dto.BooksListDTO;
import com.lib.online.service.BookService;
import com.lib.online.service.UserService;


/**
 * @author ievgen_s
 */

@Controller
@RequestMapping(value ="/rest_book")
public class RestBookController {

	 @Autowired
	    private BookService bookService;
	 @Autowired
	    private UserService userService;
	    
	    @RequestMapping(value = "{title}", method = RequestMethod.GET,
		    headers = {"Accept=text/xml, application/json"})
		    public @ResponseBody
		    Reading getBook(@PathVariable String title) {
		    return bookService.getBook(title);
		    }
	    
	    @RequestMapping(value = "{username}+{pass}/allbooks", method = RequestMethod.GET,
			    headers = {"Accept=application/xml, application/json"})
			    public @ResponseBody
			    BooksListDTO getUserBooks(@PathVariable String username, @PathVariable String pass) {
	    	   BooksListDTO result = new BooksListDTO();
	    	   result.setListBooks(this.userService.getUser(username, pass).getBooks());
			    return  result;
			    }
	    
	    @RequestMapping(value = "/allbooks", method = RequestMethod.GET,
			    headers = {"Accept=application/xml, application/json"})
			    public @ResponseBody
			    BooksListDTO getAllBooks() {
	    	   BooksListDTO result = new BooksListDTO();
	    	   result.setListBooks(this.bookService.getAllBooks());
			    return  result;
			    }
	    
	    
	    
	
}
